/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.ds2.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.its.ds2.modelo.Perfil;

/**
 *
 * @author Piter
 */
@Stateless
public class PerfilDao extends AbstractDao<Perfil> implements PerfilDaoLocal {
    @PersistenceContext(unitName = "Farmacias-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PerfilDao() {
        super(Perfil.class);
    }
    @Override
    public boolean findDuplicity(Perfil profile){
     Query q = em.createNamedQuery("Perfil.findByNombre");
     q.setParameter("nombre", profile.getNombre());
     //q.setParameter("apellidoMaterno", user.());
     //q.setParameter("apellidoPaterno", user.getApellidoPaterno());
     return !q.getResultList().isEmpty();
 } 
    @Override
     public Perfil findByid(int id){
     Query q = em.createNamedQuery("Perfil.findById");
     q.setParameter("id", id);
     //q.setParameter("apellidoMaterno", user.());
     //q.setParameter("apellidoPaterno", user.getApellidoPaterno());
     return (Perfil)q.getResultList().get(0);
 } 
}
